MovingPandas Minimum Viable Example¶

Binder

MovingPandas provides a trajectory datatype based on GeoPandas. The project home is at https://github.com/anitagraser/movingpandas

The documentation is available at https://movingpandas.readthedocs.io/en/master/

In [1]:
import warnings
warnings.filterwarnings('ignore')
In [2]:
import pandas as pd
from geopandas import gpd
import movingpandas as mpd
from datetime import datetime, timedelta

Loading trajectory data from a GeoPackage¶

The MovingPandas repository contains a demo GeoPackage file that can be loaded as follows:

In [3]:
gdf = gpd.read_file('../data/geolife_small.gpkg')
gdf.plot(figsize=(9,5))
Out[3]:
<AxesSubplot:>

After reading the trajectory point data from file, we want to construct the trajectories.

Creating a TrajectoryCollection¶

In [4]:
traj_collection = mpd.TrajectoryCollection(gdf, 'trajectory_id', t='t')
traj_collection
Out[4]:
TrajectoryCollection with 5 trajectories
In [5]:
traj_collection.plot(column='trajectory_id', legend=True, figsize=(9,5))
Out[5]:
<AxesSubplot:>

Exploring movement speed¶

In [6]:
traj_collection.plot(column='speed', linewidth=5, capstyle='round', legend=True, vmax=20, figsize=(9,5))
Out[6]:
<AxesSubplot:>

Detecting stops¶

In [7]:
detector = mpd.TrajectoryStopDetector(traj_collection)
stop_points = detector.get_stop_points(min_duration=timedelta(seconds=120), max_diameter=100)
In [8]:
ax = traj_collection.plot(figsize=(9,5))
stop_points.plot(ax=ax, color='red', markersize=100)
Out[8]:
<AxesSubplot:>
In [ ]: